<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>大数据之数据仓库Hive04_分区/分桶表与压缩 | Oct25-X</title><meta name="keywords" content="Hive"><meta name="author" content="Oct25-X"><meta name="copyright" content="Oct25-X"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="分区与分桶表一、分区表Hive 中的分区就是把一张大表的数据按照业务需要分散的存储到多个目录，每个目录就称为该表的一个分区。 在查询时通过 where 子句中的表达式选择查询所需要的分区，这样的查询效率会提高很多。 分区表基本语法创建分区表12345678create table dept_partition(	deptno int comment &amp;#x27;部门编号&amp;#x27;,    dna">
<meta property="og:type" content="article">
<meta property="og:title" content="大数据之数据仓库Hive04_分区&#x2F;分桶表与压缩">
<meta property="og:url" content="https://oct25-x.atomgit.net/oct25-xxxxx/2023/07/22/16%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%B9%8B%E6%95%B0%E6%8D%AE%E4%BB%93%E5%BA%93Hive04_%E5%88%86%E5%8C%BA%E3%80%81%E5%88%86%E6%A1%B6%E8%A1%A8%E4%B8%8E%E5%8E%8B%E7%BC%A9/index.html">
<meta property="og:site_name" content="Oct25-X">
<meta property="og:description" content="分区与分桶表一、分区表Hive 中的分区就是把一张大表的数据按照业务需要分散的存储到多个目录，每个目录就称为该表的一个分区。 在查询时通过 where 子句中的表达式选择查询所需要的分区，这样的查询效率会提高很多。 分区表基本语法创建分区表12345678create table dept_partition(	deptno int comment &amp;#x27;部门编号&amp;#x27;,    dna">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://oct25-x.atomgit.net/oct25-xxxxx/img/cover_img/ctt16.png">
<meta property="article:published_time" content="2023-07-22T04:53:29.000Z">
<meta property="article:modified_time" content="2024-02-17T14:17:36.313Z">
<meta property="article:author" content="Oct25-X">
<meta property="article:tag" content="Hive">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://oct25-x.atomgit.net/oct25-xxxxx/img/cover_img/ctt16.png"><link rel="shortcut icon" href="/oct25-xxxxx/img/logo.jpg"><link rel="canonical" href="https://oct25-x.atomgit.net/oct25-xxxxx/2023/07/22/16%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%B9%8B%E6%95%B0%E6%8D%AE%E4%BB%93%E5%BA%93Hive04_%E5%88%86%E5%8C%BA%E3%80%81%E5%88%86%E6%A1%B6%E8%A1%A8%E4%B8%8E%E5%8E%8B%E7%BC%A9/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/oct25-xxxxx/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/oct25-xxxxx/',
  algolia: undefined,
  localSearch: {"path":"search.json","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '大数据之数据仓库Hive04_分区/分桶表与压缩',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-02-17 22:17:36'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/rightMenu.css"><meta name="generator" content="Hexo 6.1.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/oct25-xxxxx/img/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data is-center"><div class="data-item"><a href="/oct25-xxxxx/archives/"><div class="headline">文章</div><div class="length-num">52</div></a></div><div class="data-item"><a href="/oct25-xxxxx/tags/"><div class="headline">标签</div><div class="length-num">17</div></a></div><div class="data-item"><a href="/oct25-xxxxx/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/oct25-xxxxx/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/oct25-xxxxx/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/oct25-xxxxx/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/oct25-xxxxx/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/oct25-xxxxx/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/oct25-xxxxx/img/top_img/top_bg15.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/oct25-xxxxx/">Oct25-X</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/oct25-xxxxx/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/oct25-xxxxx/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/oct25-xxxxx/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/oct25-xxxxx/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/oct25-xxxxx/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">大数据之数据仓库Hive04_分区/分桶表与压缩</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-07-22T04:53:29.000Z" title="发表于 2023-07-22 12:53:29">2023-07-22</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-02-17T14:17:36.313Z" title="更新于 2024-02-17 22:17:36">2024-02-17</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/oct25-xxxxx/categories/%E5%A4%A7%E6%95%B0%E6%8D%AE%E7%BB%84%E4%BB%B6/">大数据组件</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="大数据之数据仓库Hive04_分区/分桶表与压缩"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="分区与分桶表"><a href="#分区与分桶表" class="headerlink" title="分区与分桶表"></a>分区与分桶表</h1><h2 id="一、分区表"><a href="#一、分区表" class="headerlink" title="一、分区表"></a>一、分区表</h2><p>Hive 中的分区就是把一张大表的数据按照业务需要分散的存储到多个目录，每个目录就称为该表的一个分区。</p>
<p>在查询时通过 where 子句中的表达式选择查询所需要的分区，这样的查询效率会提高很多。</p>
<h3 id="分区表基本语法"><a href="#分区表基本语法" class="headerlink" title="分区表基本语法"></a>分区表基本语法</h3><h4 id="创建分区表"><a href="#创建分区表" class="headerlink" title="创建分区表"></a>创建分区表</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> dept_partition</span><br><span class="line">(</span><br><span class="line">	deptno <span class="type">int</span> comment <span class="string">&#x27;部门编号&#x27;</span>,</span><br><span class="line">    dname string comment <span class="string">&#x27;部门名称&#x27;</span>,</span><br><span class="line">    loc string comment <span class="string">&#x27;部门位置&#x27;</span></span><br><span class="line">)</span><br><span class="line">partitioned <span class="keyword">by</span> (<span class="keyword">day</span> string)</span><br><span class="line"><span class="type">row</span> format delimited fields terminated <span class="keyword">by</span> <span class="string">&#x27;\t&#x27;</span>;</span><br></pre></td></tr></table></figure>

<h4 id="分区表写数据"><a href="#分区表写数据" class="headerlink" title="分区表写数据"></a>分区表写数据</h4><ol>
<li><strong>load</strong></li>
</ol>
<p>准备数据，在 &#x2F;opt&#x2F;module&#x2F;hive-3.1.3&#x2F;datas 目录下创建文件</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">vim dept_20230601.log</span><br><span class="line">10	行政部	1700</span><br><span class="line">20	财务部	1800</span><br></pre></td></tr></table></figure>

<p>装载数据</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">load data <span class="keyword">local</span> inpath <span class="string">&#x27;/opt/module/hive-3.1.3/datas/dept_20230601.log&#x27;</span></span><br><span class="line"><span class="keyword">into</span> <span class="keyword">table</span> dept_partition </span><br><span class="line"><span class="keyword">partition</span>(<span class="keyword">day</span> <span class="operator">=</span> <span class="string">&#x27;20230601&#x27;</span>);</span><br></pre></td></tr></table></figure>

<ol start="2">
<li><strong>insert</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> <span class="keyword">table</span> dept_partition <span class="keyword">partition</span> (<span class="keyword">day</span> <span class="operator">=</span> <span class="string">&#x27;20230602&#x27;</span>)</span><br><span class="line"><span class="keyword">select</span> deptno, dname, loc</span><br><span class="line"><span class="keyword">from</span> dept_partition </span><br><span class="line"><span class="keyword">where</span> <span class="keyword">day</span> <span class="operator">=</span> <span class="string">&#x27;20230601&#x27;</span>;</span><br></pre></td></tr></table></figure>

<h4 id="分区表读数据"><a href="#分区表读数据" class="headerlink" title="分区表读数据"></a>分区表读数据</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> deptno, dname, loc, <span class="keyword">day</span></span><br><span class="line"><span class="keyword">from</span> dept_partition</span><br><span class="line"><span class="keyword">where</span> <span class="keyword">day</span> <span class="operator">=</span> <span class="string">&#x27;20230601&#x27;</span>;</span><br></pre></td></tr></table></figure>

<h4 id="分区表基本操作"><a href="#分区表基本操作" class="headerlink" title="分区表基本操作"></a>分区表基本操作</h4><ol>
<li><strong>查看所有分区信息</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">show</span> partitions dept_partition;</span><br></pre></td></tr></table></figure>

<ol start="2">
<li><strong>增加分区</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">--创建单个分区</span></span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> dept_partition <span class="keyword">add</span> <span class="keyword">partition</span>(<span class="keyword">day</span> <span class="operator">=</span> <span class="string">&#x27;20230603&#x27;</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">--创建多个分区</span></span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> dept_partition <span class="keyword">add</span> </span><br><span class="line"><span class="keyword">partition</span>(<span class="keyword">day</span> <span class="operator">=</span> <span class="string">&#x27;20230604&#x27;</span>) <span class="keyword">partition</span>(<span class="keyword">day</span> <span class="operator">=</span> <span class="string">&#x27;20230605&#x27;</span>);</span><br></pre></td></tr></table></figure>

<ol start="3">
<li><strong>删除分区</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">--删除单个分区</span></span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> dept_partition <span class="keyword">drop</span> <span class="keyword">partition</span>(<span class="keyword">day</span> <span class="operator">=</span> <span class="string">&#x27;20230603&#x27;</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">--删除多个分区</span></span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> dept_partition <span class="keyword">drop</span></span><br><span class="line"><span class="keyword">partition</span>(<span class="keyword">day</span> <span class="operator">=</span> <span class="string">&#x27;20230604&#x27;</span>), <span class="keyword">partition</span>(<span class="keyword">day</span> <span class="operator">=</span> <span class="string">&#x27;20230605&#x27;</span>);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>注意：同时删除多个分区时，多个分区之间需要有逗号间隔</p>
</blockquote>
<ol start="4">
<li><strong>修复分区</strong></li>
</ol>
<p>Hive 将分区表的所有分区信息都保存在了元数据中，只有元数据与 HDFS 上的分区路径一致时，分区表才能正常读写数据。若用户手动创建&#x2F;删除分区路径，Hive 都是感知不到的，这样就会导致 Hive 的元数据和 HDFS 的分区路径不一致。</p>
<p>再比如，若分区表为外部表，用户执行 drop partition 命令后，分区元数据会被删除，而 HDFS 的分区路径不会被删除，同样会导致 Hive 的元数据和 HDFS 的分区路径不一致。</p>
<p>若出现元数据和 HDFS 路径不一致的情况，可通过如下几种手段进行修复:</p>
<p><strong>add partition</strong>：若手动创建 HDFS 的分区路径，Hive无法识别，可通过 add partition 命令增加分区元数据信息，从而使元数据和分区路径保持一致。</p>
<p><strong>drop partition</strong>：若手动删除 HDFS 的分区路径，Hive 无法识别，可通过 drop partition 命令删除分区元数据信息，从而使元数据和分区路径保持一致。</p>
<p><strong>msck</strong>：若分区元数据和 HDFS的 分区路径不一致，还可使用 msck 命令进行修复</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">msck repair <span class="keyword">table</span> table_name [<span class="keyword">add</span><span class="operator">/</span><span class="keyword">drop</span><span class="operator">/</span>sync <span class="keyword">partition</span>];</span><br></pre></td></tr></table></figure>

<h3 id="级分区表"><a href="#级分区表" class="headerlink" title="级分区表"></a>级分区表</h3><p>思考：如果一天内的日志数据量也很大，如何再将数据拆分?答案是二级分区表，例如可以在按天分区的基础上，再对每天的数据按小时进行分区。</p>
<ol>
<li><strong>二级分区表建表语句</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> dept_partition2</span><br><span class="line">(</span><br><span class="line">	deptno <span class="type">int</span> comment <span class="string">&#x27;部门编号&#x27;</span>,</span><br><span class="line">    dname string comment <span class="string">&#x27;部门名称&#x27;</span>,</span><br><span class="line">    loc string comment <span class="string">&#x27;部门位置&#x27;</span></span><br><span class="line">)</span><br><span class="line">partitioned <span class="keyword">by</span> (<span class="keyword">day</span> string, <span class="keyword">hour</span> string)</span><br><span class="line"><span class="type">row</span> format delimited fields terminated <span class="keyword">by</span> <span class="string">&#x27;\t&#x27;</span>;</span><br></pre></td></tr></table></figure>

<ol start="2">
<li><strong>装载数据</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">load data <span class="keyword">local</span> inpath <span class="string">&#x27;/opt/module/hive-3.1.3/datas/dept_20230605.log&#x27;</span></span><br><span class="line"><span class="keyword">into</span> <span class="keyword">table</span> dept_partition2</span><br><span class="line"><span class="keyword">partition</span> (<span class="keyword">day</span> <span class="operator">=</span> <span class="string">&#x27;20230605&#x27;</span>, <span class="keyword">hour</span> <span class="operator">=</span> <span class="string">&#x27;12&#x27;</span>);</span><br></pre></td></tr></table></figure>

<ol start="3">
<li><strong>查询分区数据</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> dept_partition2 <span class="keyword">where</span> <span class="keyword">day</span> <span class="operator">=</span> <span class="string">&#x27;20230605&#x27;</span> <span class="keyword">and</span> <span class="keyword">hour</span> <span class="operator">=</span> <span class="string">&#x27;12&#x27;</span>;</span><br></pre></td></tr></table></figure>

<h3 id="动态分区"><a href="#动态分区" class="headerlink" title="动态分区"></a>动态分区</h3><ol>
<li><strong>动态分区功能开关（默认true，开启）</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">set</span> hive.exec.dynamic.partition<span class="operator">=</span><span class="literal">true</span>;</span><br></pre></td></tr></table></figure>

<ol start="2">
<li><strong>严格模式和非严格模式</strong></li>
</ol>
<p>动态分区的模式，默认 strict（严格模式），要求必须指定至少一个分区为静态分区，nonstrict（非严格模式）允许所有的分区字段都使用动态分区</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">set</span> hive.exec.dynamic.partition.mode<span class="operator">=</span>nonstrict;</span><br></pre></td></tr></table></figure>

<ol start="3">
<li><strong>一条insert语句可同时创建的最大的分区个数，默认为1000</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">set</span> hive.exec.max.dynamic.partitions<span class="operator">=</span><span class="number">1000</span>;</span><br></pre></td></tr></table></figure>

<ol start="4">
<li><strong>单个Mapper或者Reducer可同时创建的最大的分区个数，默认为100</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">set</span> hive.exec.max.dynamic.partitions.pernode<span class="operator">=</span><span class="number">100</span>;</span><br></pre></td></tr></table></figure>

<ol start="5">
<li><strong>一条insert语句可以创建的最大的文件个数，默认100000</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hive.exec.max.created.files<span class="operator">=</span><span class="number">100000</span>;</span><br></pre></td></tr></table></figure>

<ol start="6">
<li><strong>当查询结果为空时且进行动态分区时，是否抛出异常，默认false</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hive.error.on.empty.partition<span class="operator">=</span><span class="literal">false</span>;</span><br></pre></td></tr></table></figure>

<h3 id="示例"><a href="#示例" class="headerlink" title="示例"></a>示例</h3><p>需求：将 dept 表中的数据按照地区（loc字段），插入到目标表 dept_partition_dynamic 的相应分区中。</p>
<ol>
<li><strong>创建目标分区表</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> dept_partition_dynamic(</span><br><span class="line">    id <span class="type">int</span>, </span><br><span class="line">    name string</span><br><span class="line">) </span><br><span class="line">partitioned <span class="keyword">by</span> (loc <span class="type">int</span>) </span><br><span class="line"><span class="type">row</span> format delimited fields terminated <span class="keyword">by</span> <span class="string">&#x27;\t&#x27;</span>;</span><br></pre></td></tr></table></figure>

<ol start="2">
<li><strong>设置动态分区</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">set</span> hive.exec.dynamic.partition.mode <span class="operator">=</span> nonstrict;</span><br></pre></td></tr></table></figure>

<ol start="3">
<li><strong>插入数据</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> <span class="keyword">table</span> dept_partition_dynamic <span class="keyword">partition</span>(loc)</span><br><span class="line"><span class="keyword">select</span> deptno,dname,loc</span><br><span class="line"><span class="keyword">from</span> dept;</span><br></pre></td></tr></table></figure>

<ol start="4">
<li><strong>查看目标分区表的分区情况</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">show</span> partitions dept_partition_dynamic;</span><br></pre></td></tr></table></figure>

<h2 id="二、分桶表"><a href="#二、分桶表" class="headerlink" title="二、分桶表"></a>二、分桶表</h2><p>分区提供一个隔离数据和优化查询的便利方式。不过，并非所有的数据集都可形成合理的分区。对于一张表或者分区，Hive 可以进一步组织成桶，也就是更为细粒度的数据范围划分，分区针对的是数据的存储路径，分桶针对的是数据文件。</p>
<p>分桶表的基本原理是，首先为每行数据计算一个指定字段的数据的hash值，然后模以一个指定的分桶数，最后将取模运算结果相同的行，写入同一个文件中，这个文件就称为一个分桶（bucket）。</p>
<h3 id="分桶表基本语法"><a href="#分桶表基本语法" class="headerlink" title="分桶表基本语法"></a>分桶表基本语法</h3><ol>
<li><strong>建表语句</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> stu_buck (id <span class="type">int</span>, name string)</span><br><span class="line">clustered <span class="keyword">by</span> (id)</span><br><span class="line"><span class="keyword">into</span> <span class="number">4</span> buckets</span><br><span class="line"><span class="type">row</span> foramt delimited fields terminated <span class="keyword">by</span> <span class="string">&#x27;\t&#x27;</span>;</span><br></pre></td></tr></table></figure>

<ol start="2">
<li><strong>装载数据</strong></li>
</ol>
<p>在 &#x2F;opt&#x2F;module&#x2F;hive-3.1.3&#x2F;datas&#x2F; 目录下创建数据文件 student.txt</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1001</span>	student1</span><br><span class="line"><span class="number">1002</span>	student2</span><br><span class="line"><span class="number">1003</span>	student3</span><br><span class="line"><span class="number">1004</span>	student4</span><br><span class="line"><span class="number">1005</span>	student5</span><br><span class="line"><span class="number">1006</span>	student6</span><br><span class="line"><span class="number">1007</span>	student7</span><br><span class="line"><span class="number">1008</span>	student8</span><br><span class="line"><span class="number">1009</span>	student9</span><br><span class="line"><span class="number">1010</span>	student10</span><br><span class="line"><span class="number">1011</span>	student11</span><br><span class="line"><span class="number">1012</span>	student12</span><br><span class="line"><span class="number">1013</span>	student13</span><br><span class="line"><span class="number">1014</span>	student14</span><br><span class="line"><span class="number">1015</span>	student15</span><br><span class="line"><span class="number">1016</span>	student16</span><br></pre></td></tr></table></figure>

<ol start="3">
<li><strong>导入数据到表中</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">load data <span class="keyword">local</span> inpath <span class="string">&#x27;/opt/module/hive-3.1.3/datas/student.txt&#x27;</span></span><br><span class="line"><span class="keyword">into</span> <span class="keyword">table</span> stu_buck;</span><br></pre></td></tr></table></figure>

<p>说明：Hive 新版本 load 数据可以直接跑 MapReduce，老版的 Hive 需要将数据传到一张表里，再通过查询的方式导入到分桶表里面。</p>
<ol start="4">
<li><strong>可以到 HDFS 上查看表所在目录</strong></li>
</ol>
<h3 id="分桶表排序"><a href="#分桶表排序" class="headerlink" title="分桶表排序"></a>分桶表排序</h3><ol>
<li><strong>建表语句</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> stu_buck_sort (id <span class="type">int</span>, name string)</span><br><span class="line">clustered <span class="keyword">by</span> (id) sorted <span class="keyword">by</span> (id)</span><br><span class="line"><span class="keyword">into</span> <span class="number">4</span> buckets</span><br><span class="line"><span class="type">row</span> foramt delimited fields terminated <span class="keyword">by</span> <span class="string">&#x27;\t&#x27;</span>;</span><br></pre></td></tr></table></figure>

<ol start="2">
<li><strong>装载数据</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">load data <span class="keyword">local</span> inpath <span class="string">&#x27;/opt/module/hive-3.1.3/datas/student.txt&#x27;</span></span><br><span class="line"><span class="keyword">into</span> <span class="keyword">table</span> stu_buck_sort;</span><br></pre></td></tr></table></figure>

<h1 id="文件格式和压缩"><a href="#文件格式和压缩" class="headerlink" title="文件格式和压缩"></a>文件格式和压缩</h1><h2 id="一、Hadoop-压缩概述"><a href="#一、Hadoop-压缩概述" class="headerlink" title="一、Hadoop 压缩概述"></a>一、Hadoop 压缩概述</h2><table>
<thead>
<tr>
<th>压缩格式</th>
<th>算法</th>
<th>文件扩展名</th>
<th>是否可切分</th>
</tr>
</thead>
<tbody><tr>
<td>DEFLATE</td>
<td>DEFLATE</td>
<td>.deflate</td>
<td>否</td>
</tr>
<tr>
<td>Gzip</td>
<td>DEFLATE</td>
<td>.gz</td>
<td>否</td>
</tr>
<tr>
<td>bzip2</td>
<td>bzip2</td>
<td>.bz2</td>
<td><strong>是</strong></td>
</tr>
<tr>
<td>LZO</td>
<td>LZO</td>
<td>.lzo</td>
<td><strong>是</strong></td>
</tr>
<tr>
<td>Snappy</td>
<td>Snappy</td>
<td>.snappy</td>
<td>否</td>
</tr>
</tbody></table>
<p>为了支持多种压缩&#x2F;解压缩算法，Hadoop引入了编码&#x2F;解码器，如下表所示：</p>
<p>Hadoop 查看支持压缩的方式 hadoop checknative。</p>
<p>Hadoop 在 driver 端设置压缩。</p>
<table>
<thead>
<tr>
<th>压缩格式</th>
<th>对应的编码&#x2F;解码器</th>
</tr>
</thead>
<tbody><tr>
<td>DEFLATE</td>
<td>org.apache.hadoop.io.compress.DefaultCodec</td>
</tr>
<tr>
<td>gzip</td>
<td>org.apache.hadoop.io.compress.GzipCodec</td>
</tr>
<tr>
<td>bzip2</td>
<td>org.apache.hadoop.io.compress.BZip2Codec</td>
</tr>
<tr>
<td>LZO</td>
<td>com.hadoop.compression.lzo.LzopCodec</td>
</tr>
<tr>
<td>Snappy</td>
<td>org.apache.hadoop.io.compress.SnappyCodec</td>
</tr>
</tbody></table>
<p>压缩性能的比较：</p>
<table>
<thead>
<tr>
<th>压缩算法</th>
<th>原始文件大小</th>
<th>压缩文件大小</th>
<th>压缩速度</th>
<th>解压速度</th>
</tr>
</thead>
<tbody><tr>
<td>gzip</td>
<td>8.3GB</td>
<td>1.8GB</td>
<td>17.5MB&#x2F;s</td>
<td>58MB&#x2F;s</td>
</tr>
<tr>
<td>bzip2</td>
<td>8.3GB</td>
<td>1.1GB</td>
<td>2.4MB&#x2F;s</td>
<td>9.5MB&#x2F;s</td>
</tr>
<tr>
<td>LZO</td>
<td>8.3GB</td>
<td>2.9GB</td>
<td>49.3MB&#x2F;s</td>
<td>74.6MB&#x2F;s</td>
</tr>
</tbody></table>
<h2 id="二、Hive-文件格式"><a href="#二、Hive-文件格式" class="headerlink" title="二、Hive 文件格式"></a>二、Hive 文件格式</h2><p>为 Hive 表中的数据选择一个合适的文件格式，对提高查询性能的提高是十分有益的。Hive 表数据的存储格式，可以选择text file、orc、parquet、sequence file等。</p>
<h3 id="TextFile"><a href="#TextFile" class="headerlink" title="TextFile"></a>TextFile</h3><p>文本文件是 Hive 默认使用的文件格式，文本文件中的一行内容，就对应 Hive 表中的一行记录。</p>
<p>可通过以下建表语句指定文件格式为文本文件:</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> textfile_table (<span class="keyword">column</span> specs)</span><br><span class="line">stored <span class="keyword">as</span> textfile</span><br></pre></td></tr></table></figure>

<h3 id="ORC"><a href="#ORC" class="headerlink" title="ORC"></a>ORC</h3><p>ORC（Optimized Row Columnar）file format 是 Hive 0.11 版里引入的一种**<code>列式存储</code>**的文件格式。</p>
<p>ORC 文件能够提高 Hive 读写数据和处理数据的性能。</p>
<p>与列式存储相对的是行式存储，下图是两者的对比：</p>
<p><img src="/oct25-xxxxx/img/hive/04_%E8%A1%8C%E5%88%97%E5%AD%98%E5%82%A8%E6%AF%94%E8%BE%83.png" alt="行列存储比较"></p>
<p>如图所示左边为逻辑表，右边第一个为行式存储，第二个为列式存储。</p>
<ol>
<li><strong>行存储特点</strong></li>
</ol>
<p>查询满足条件的一整行数据的时候，列存储则需要去每个聚集的字段找到对应的每个列的值，行存储只需要找到其中一个值，其余的值都在相邻地方，所以此时行存储查询的速度更快。</p>
<ol start="2">
<li><strong>列存储的特点</strong></li>
</ol>
<p>因为每个字段的数据聚集存储，在查询只需要少数几个字段的时候，能大大减少读取的数据量；每个字段的数据类型一定是相同的，列式存储可以针对性的设计更好的设计压缩算法。</p>
<p>前文提到的 text file 和 sequence file 都是基于行存储的，orc 和 parquet 是基于列式存储的。</p>
<p>orc 文件的具体结构如下图所示：</p>
<p><img src="/oct25-xxxxx/img/hive/05_orc.png" alt="ORC"></p>
<p><strong>Index Data</strong>：一个轻量级的 index，默认是为各列每隔1W行做一个索引。每个索引会记录第n万行的位置，和最近一万行的最大值和最小值等信息。</p>
<p><strong>Row Data</strong>：存的是具体的数据，按列进行存储，并对每个列进行编码，分成多个 Stream 来存储。</p>
<p><strong>Stripe Footer</strong>：存放的是各个 Stream 的位置以及各 column 的编码信息。</p>
<ol start="3">
<li><strong>建表语句</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> orc_table(clomn specs)</span><br><span class="line">stored <span class="keyword">as</span> orc</span><br><span class="line">tblproperties (property_name <span class="operator">=</span> property_value, ...);</span><br></pre></td></tr></table></figure>

<p>ORC文件格式支持的参数如下：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>orc.compress</td>
<td>ZLIB</td>
<td>压缩格式，可选项：NONE、ZLIB,、SNAPPY</td>
</tr>
<tr>
<td>orc.compress.size</td>
<td>262,144</td>
<td>每个压缩块的大小（ORC文件是分块压缩的）</td>
</tr>
<tr>
<td>orc.stripe.size</td>
<td>67,108,864</td>
<td>每个stripe的大小</td>
</tr>
<tr>
<td>orc.row.index.stride</td>
<td>10,000</td>
<td>索引步长（每隔多少行数据建一条索引）</td>
</tr>
</tbody></table>
<h3 id="Parquet"><a href="#Parquet" class="headerlink" title="Parquet"></a>Parquet</h3><p>Parquet 文件是 Hadoop 生态中的一个通用的文件格式，它也是一个列式存储的文件格式。</p>
<ol>
<li><strong>建表语句</strong></li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> parquet_table(clomn specs)</span><br><span class="line">stored <span class="keyword">as</span> parquet</span><br><span class="line">tblproperties (property_name <span class="operator">=</span> property_value, ...);</span><br></pre></td></tr></table></figure>

<p>支持的参数如下：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>parquet.compression</td>
<td>uncompressed</td>
<td>压缩格式，可选项：uncompressed，snappy，gzip，lzo，brotli，lz4</td>
</tr>
<tr>
<td>parquet.block.size</td>
<td>134217728</td>
<td>行组大小，通常与HDFS块大小保持一致</td>
</tr>
<tr>
<td>parquet.page.size</td>
<td>1048576</td>
<td>页大小</td>
</tr>
</tbody></table>
<h2 id="三、压缩"><a href="#三、压缩" class="headerlink" title="三、压缩"></a>三、压缩</h2><p>在 Hive 表中和计算过程中，保持数据的压缩，对磁盘空间的有效利用和提高查询性能都是十分有益的。</p>
<h3 id="Hive-表数据进行压缩"><a href="#Hive-表数据进行压缩" class="headerlink" title="Hive 表数据进行压缩"></a>Hive 表数据进行压缩</h3><h4 id="TextFile-1"><a href="#TextFile-1" class="headerlink" title="TextFile"></a>TextFile</h4><p>若一张表的文件类型为 TextFile，若需要对该表中的数据进行压缩，多数情况下，无需在建表语句做出声明。直接将压缩后的文件导入到该表即可，Hive 在查询表中数据时，可自动识别其压缩格式，进行解压。</p>
<p>需要注意的是，在执行往表中导入数据的SQL语句时，用户需设置以下参数，来保证写入表中的数据是被压缩的。</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">--sql语句的最终输出结果是否压缩</span></span><br><span class="line"><span class="keyword">set</span> hive.exec.compress.output<span class="operator">=</span><span class="literal">true</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">--输出结果的压缩枨（以snappy为例）</span></span><br><span class="line"><span class="keyword">set</span> mapreduce.output.fileoutputformat.compress.codec<span class="operator">=</span>org.apache.hadoop.io.compress.SnappyCodec;</span><br></pre></td></tr></table></figure>

<h4 id="ORC-1"><a href="#ORC-1" class="headerlink" title="ORC"></a>ORC</h4><p>若一张表的文件类型为ORC，若需要对该表数据进行压缩，需在建表语句中声明压缩格式如下：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> orc_table(<span class="keyword">column</span> specs)</span><br><span class="line">tblproperties (&quot;orc.comress&quot;<span class="operator">=</span>&quot;snappy&quot;);</span><br></pre></td></tr></table></figure>

<h4 id="Parquet-1"><a href="#Parquet-1" class="headerlink" title="Parquet"></a>Parquet</h4><p>若一张表的文件类型为 Parquet，若需要对该表数据进行压缩，需在建表语句中声明压缩格式如下：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> orc_table(column_specs)</span><br><span class="line">stored <span class="keyword">as</span> parquet</span><br><span class="line">tblproperties (&quot;parquet.compression&quot;<span class="operator">=</span>&quot;snappy&quot;);</span><br></pre></td></tr></table></figure>

<h3 id="计算过程中使用压缩"><a href="#计算过程中使用压缩" class="headerlink" title="计算过程中使用压缩"></a>计算过程中使用压缩</h3><h4 id="单个-MR-中间结果进行压缩"><a href="#单个-MR-中间结果进行压缩" class="headerlink" title="单个 MR 中间结果进行压缩"></a>单个 MR 中间结果进行压缩</h4><p>单个 MR 的中间结果是指 Mapper 输出的数据，对其进行压缩可降低 shuffle 阶段的网络 IO，可通过以下参数进行配置：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">--开启MapReduce中间数据压缩功能</span></span><br><span class="line"><span class="keyword">set</span> mapreduce.map.output.compress<span class="operator">=</span><span class="literal">true</span>;</span><br><span class="line"><span class="comment">--设置MapReduce中间数据数据的压缩方式（以下示例为snappy）</span></span><br><span class="line"><span class="keyword">set</span> mapreduce.map.output.compress.codec<span class="operator">=</span>org.apache.hadoop.io.compress.SnappyCodec;</span><br></pre></td></tr></table></figure>

<h4 id="单条-SQL-语句的中间结果进行压缩"><a href="#单条-SQL-语句的中间结果进行压缩" class="headerlink" title="单条 SQL 语句的中间结果进行压缩"></a>单条 SQL 语句的中间结果进行压缩</h4><p>单条SQL语句的中间结果是指，两个MR（一条SQL语句可能需要通过MR进行计算）之间的临时数据，可通过以下参数进行配置：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">--是否对两个 MR 之间的临时数据进行压缩</span></span><br><span class="line"><span class="keyword">set</span> hive.exec.compress.intermediate<span class="operator">=</span><span class="literal">true</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">--压缩格式（以snappy为例）</span></span><br><span class="line"><span class="keyword">set</span> hive.intermediate.compression.codec<span class="operator">=</span>org.apache.hadoop.io.compress.SnappyCodec;</span><br></pre></td></tr></table></figure>







































</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">Oct25-X</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://oct25-x.atomgit.net/oct25-xxxxx/2023/07/22/16%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%B9%8B%E6%95%B0%E6%8D%AE%E4%BB%93%E5%BA%93Hive04_%E5%88%86%E5%8C%BA%E3%80%81%E5%88%86%E6%A1%B6%E8%A1%A8%E4%B8%8E%E5%8E%8B%E7%BC%A9/">https://oct25-x.atomgit.net/oct25-xxxxx/2023/07/22/16%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%B9%8B%E6%95%B0%E6%8D%AE%E4%BB%93%E5%BA%93Hive04_%E5%88%86%E5%8C%BA%E3%80%81%E5%88%86%E6%A1%B6%E8%A1%A8%E4%B8%8E%E5%8E%8B%E7%BC%A9/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://oct25-x.atomgit.net/oct25-xxxxx" target="_blank">Oct25-X</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/oct25-xxxxx/tags/Hive/">Hive</a></div><div class="post_share"><div class="social-share" data-image="/oct25-xxxxx/img/cover_img/ctt16.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/oct25-xxxxx/2023/07/23/17%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%B9%8B%E6%95%B0%E6%8D%AE%E4%BB%93%E5%BA%93Hive05_%E4%BC%81%E4%B8%9A%E7%BA%A7%E8%B0%83%E4%BC%98/"><img class="prev-cover" src="/oct25-xxxxx/img/cover_img/ctt17.png" onerror="onerror=null;src='/oct25-xxxxx/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">大数据之数据仓库Hive05_企业级调优</div></div></a></div><div class="next-post pull-right"><a href="/oct25-xxxxx/2023/07/18/15%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%B9%8B%E6%95%B0%E6%8D%AE%E4%BB%93%E5%BA%93Hive03_%E6%9F%A5%E8%AF%A2%E5%92%8C%20Hive%20%E5%87%BD%E6%95%B0/"><img class="next-cover" src="/oct25-xxxxx/img/cover_img/ctt15.png" onerror="onerror=null;src='/oct25-xxxxx/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">大数据之数据仓库Hive03_查询和 Hive 函数</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/oct25-xxxxx/2023/07/16/14%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%B9%8B%E6%95%B0%E6%8D%AE%E4%BB%93%E5%BA%93Hive02_DDL%20%E5%92%8C%20DML/" title="大数据之数据仓库Hive02_DDL 与 DML"><img class="cover" src="/oct25-xxxxx/img/cover_img/ctt14.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-07-16</div><div class="title">大数据之数据仓库Hive02_DDL 与 DML</div></div></a></div><div><a href="/oct25-xxxxx/2023/07/15/13%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%B9%8B%E6%95%B0%E6%8D%AE%E4%BB%93%E5%BA%93Hive01_%E5%9F%BA%E7%A1%80/" title="大数据之数据仓库Hive01_基础"><img class="cover" src="/oct25-xxxxx/img/cover_img/ctt13.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-07-15</div><div class="title">大数据之数据仓库Hive01_基础</div></div></a></div><div><a href="/oct25-xxxxx/2023/07/18/15%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%B9%8B%E6%95%B0%E6%8D%AE%E4%BB%93%E5%BA%93Hive03_%E6%9F%A5%E8%AF%A2%E5%92%8C%20Hive%20%E5%87%BD%E6%95%B0/" title="大数据之数据仓库Hive03_查询和 Hive 函数"><img class="cover" src="/oct25-xxxxx/img/cover_img/ctt15.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-07-18</div><div class="title">大数据之数据仓库Hive03_查询和 Hive 函数</div></div></a></div><div><a href="/oct25-xxxxx/2023/07/23/17%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%B9%8B%E6%95%B0%E6%8D%AE%E4%BB%93%E5%BA%93Hive05_%E4%BC%81%E4%B8%9A%E7%BA%A7%E8%B0%83%E4%BC%98/" title="大数据之数据仓库Hive05_企业级调优"><img class="cover" src="/oct25-xxxxx/img/cover_img/ctt17.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-07-23</div><div class="title">大数据之数据仓库Hive05_企业级调优</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/oct25-xxxxx/img/avatar.jpg" onerror="this.onerror=null;this.src='/oct25-xxxxx/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Oct25-X</div><div class="author-info__description"></div></div><div class="card-info-data is-center"><div class="card-info-data-item"><a href="/oct25-xxxxx/archives/"><div class="headline">文章</div><div class="length-num">52</div></a></div><div class="card-info-data-item"><a href="/oct25-xxxxx/tags/"><div class="headline">标签</div><div class="length-num">17</div></a></div><div class="card-info-data-item"><a href="/oct25-xxxxx/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%88%86%E5%8C%BA%E4%B8%8E%E5%88%86%E6%A1%B6%E8%A1%A8"><span class="toc-number">1.</span> <span class="toc-text">分区与分桶表</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%80%E3%80%81%E5%88%86%E5%8C%BA%E8%A1%A8"><span class="toc-number">1.1.</span> <span class="toc-text">一、分区表</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%86%E5%8C%BA%E8%A1%A8%E5%9F%BA%E6%9C%AC%E8%AF%AD%E6%B3%95"><span class="toc-number">1.1.1.</span> <span class="toc-text">分区表基本语法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E5%88%86%E5%8C%BA%E8%A1%A8"><span class="toc-number">1.1.1.1.</span> <span class="toc-text">创建分区表</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%86%E5%8C%BA%E8%A1%A8%E5%86%99%E6%95%B0%E6%8D%AE"><span class="toc-number">1.1.1.2.</span> <span class="toc-text">分区表写数据</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%86%E5%8C%BA%E8%A1%A8%E8%AF%BB%E6%95%B0%E6%8D%AE"><span class="toc-number">1.1.1.3.</span> <span class="toc-text">分区表读数据</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%86%E5%8C%BA%E8%A1%A8%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C"><span class="toc-number">1.1.1.4.</span> <span class="toc-text">分区表基本操作</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BA%A7%E5%88%86%E5%8C%BA%E8%A1%A8"><span class="toc-number">1.1.2.</span> <span class="toc-text">级分区表</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8A%A8%E6%80%81%E5%88%86%E5%8C%BA"><span class="toc-number">1.1.3.</span> <span class="toc-text">动态分区</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%A4%BA%E4%BE%8B"><span class="toc-number">1.1.4.</span> <span class="toc-text">示例</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%8C%E3%80%81%E5%88%86%E6%A1%B6%E8%A1%A8"><span class="toc-number">1.2.</span> <span class="toc-text">二、分桶表</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%86%E6%A1%B6%E8%A1%A8%E5%9F%BA%E6%9C%AC%E8%AF%AD%E6%B3%95"><span class="toc-number">1.2.1.</span> <span class="toc-text">分桶表基本语法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%86%E6%A1%B6%E8%A1%A8%E6%8E%92%E5%BA%8F"><span class="toc-number">1.2.2.</span> <span class="toc-text">分桶表排序</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%96%87%E4%BB%B6%E6%A0%BC%E5%BC%8F%E5%92%8C%E5%8E%8B%E7%BC%A9"><span class="toc-number">2.</span> <span class="toc-text">文件格式和压缩</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%80%E3%80%81Hadoop-%E5%8E%8B%E7%BC%A9%E6%A6%82%E8%BF%B0"><span class="toc-number">2.1.</span> <span class="toc-text">一、Hadoop 压缩概述</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%8C%E3%80%81Hive-%E6%96%87%E4%BB%B6%E6%A0%BC%E5%BC%8F"><span class="toc-number">2.2.</span> <span class="toc-text">二、Hive 文件格式</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#TextFile"><span class="toc-number">2.2.1.</span> <span class="toc-text">TextFile</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ORC"><span class="toc-number">2.2.2.</span> <span class="toc-text">ORC</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Parquet"><span class="toc-number">2.2.3.</span> <span class="toc-text">Parquet</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%89%E3%80%81%E5%8E%8B%E7%BC%A9"><span class="toc-number">2.3.</span> <span class="toc-text">三、压缩</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Hive-%E8%A1%A8%E6%95%B0%E6%8D%AE%E8%BF%9B%E8%A1%8C%E5%8E%8B%E7%BC%A9"><span class="toc-number">2.3.1.</span> <span class="toc-text">Hive 表数据进行压缩</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#TextFile-1"><span class="toc-number">2.3.1.1.</span> <span class="toc-text">TextFile</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ORC-1"><span class="toc-number">2.3.1.2.</span> <span class="toc-text">ORC</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Parquet-1"><span class="toc-number">2.3.1.3.</span> <span class="toc-text">Parquet</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%A1%E7%AE%97%E8%BF%87%E7%A8%8B%E4%B8%AD%E4%BD%BF%E7%94%A8%E5%8E%8B%E7%BC%A9"><span class="toc-number">2.3.2.</span> <span class="toc-text">计算过程中使用压缩</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%8D%95%E4%B8%AA-MR-%E4%B8%AD%E9%97%B4%E7%BB%93%E6%9E%9C%E8%BF%9B%E8%A1%8C%E5%8E%8B%E7%BC%A9"><span class="toc-number">2.3.2.1.</span> <span class="toc-text">单个 MR 中间结果进行压缩</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%8D%95%E6%9D%A1-SQL-%E8%AF%AD%E5%8F%A5%E7%9A%84%E4%B8%AD%E9%97%B4%E7%BB%93%E6%9E%9C%E8%BF%9B%E8%A1%8C%E5%8E%8B%E7%BC%A9"><span class="toc-number">2.3.2.2.</span> <span class="toc-text">单条 SQL 语句的中间结果进行压缩</span></a></li></ol></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/oct25-xxxxx/2024/02/24/52%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%B9%8B%E5%A4%9A%E8%8C%83%E5%BC%8F%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80Scala09_%E9%9A%90%E5%BC%8F%E8%BD%AC%E6%8D%A2%E3%80%81%E5%BC%82%E5%B8%B8%E5%92%8C%E6%B3%9B%E5%9E%8B/" title="大数据之多范式编程语言 Scala09_隐式转换、异常和泛型"><img src="/oct25-xxxxx/img/cover_img/ctt52.png" onerror="this.onerror=null;this.src='/oct25-xxxxx/img/404.jpg'" alt="大数据之多范式编程语言 Scala09_隐式转换、异常和泛型"/></a><div class="content"><a class="title" href="/oct25-xxxxx/2024/02/24/52%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%B9%8B%E5%A4%9A%E8%8C%83%E5%BC%8F%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80Scala09_%E9%9A%90%E5%BC%8F%E8%BD%AC%E6%8D%A2%E3%80%81%E5%BC%82%E5%B8%B8%E5%92%8C%E6%B3%9B%E5%9E%8B/" title="大数据之多范式编程语言 Scala09_隐式转换、异常和泛型">大数据之多范式编程语言 Scala09_隐式转换、异常和泛型</a><time datetime="2024-02-24T04:55:34.000Z" title="发表于 2024-02-24 12:55:34">2024-02-24</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/oct25-xxxxx/2024/02/24/51%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%B9%8B%E5%A4%9A%E8%8C%83%E5%BC%8F%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80Scala08_%E6%A8%A1%E5%BC%8F%E5%8C%B9%E9%85%8D/" title="大数据之多范式编程语言 Scala08_模式匹配"><img src="/oct25-xxxxx/img/cover_img/ctt51.png" onerror="this.onerror=null;this.src='/oct25-xxxxx/img/404.jpg'" alt="大数据之多范式编程语言 Scala08_模式匹配"/></a><div class="content"><a class="title" href="/oct25-xxxxx/2024/02/24/51%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%B9%8B%E5%A4%9A%E8%8C%83%E5%BC%8F%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80Scala08_%E6%A8%A1%E5%BC%8F%E5%8C%B9%E9%85%8D/" title="大数据之多范式编程语言 Scala08_模式匹配">大数据之多范式编程语言 Scala08_模式匹配</a><time datetime="2024-02-24T00:46:12.000Z" title="发表于 2024-02-24 08:46:12">2024-02-24</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/oct25-xxxxx/2024/02/22/50%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%B9%8B%E5%A4%9A%E8%8C%83%E5%BC%8F%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80Scala07_%E9%9B%86%E5%90%88/" title="大数据之多范式编程语言 Scala07_集合"><img src="/oct25-xxxxx/img/cover_img/ctt50.png" onerror="this.onerror=null;this.src='/oct25-xxxxx/img/404.jpg'" alt="大数据之多范式编程语言 Scala07_集合"/></a><div class="content"><a class="title" href="/oct25-xxxxx/2024/02/22/50%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%B9%8B%E5%A4%9A%E8%8C%83%E5%BC%8F%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80Scala07_%E9%9B%86%E5%90%88/" title="大数据之多范式编程语言 Scala07_集合">大数据之多范式编程语言 Scala07_集合</a><time datetime="2024-02-22T08:16:10.000Z" title="发表于 2024-02-22 16:16:10">2024-02-22</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/oct25-xxxxx/2024/02/21/49%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%B9%8B%E5%A4%9A%E8%8C%83%E5%BC%8F%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80Scala06_%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/" title="大数据之多范式编程语言 Scala06_面向对象"><img src="/oct25-xxxxx/img/cover_img/ctt49.png" onerror="this.onerror=null;this.src='/oct25-xxxxx/img/404.jpg'" alt="大数据之多范式编程语言 Scala06_面向对象"/></a><div class="content"><a class="title" href="/oct25-xxxxx/2024/02/21/49%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%B9%8B%E5%A4%9A%E8%8C%83%E5%BC%8F%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80Scala06_%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/" title="大数据之多范式编程语言 Scala06_面向对象">大数据之多范式编程语言 Scala06_面向对象</a><time datetime="2024-02-21T07:01:10.000Z" title="发表于 2024-02-21 15:01:10">2024-02-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/oct25-xxxxx/2024/02/20/48%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%B9%8B%E5%A4%9A%E8%8C%83%E5%BC%8F%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80Scala05_%E5%87%BD%E6%95%B0%E5%BC%8F%E7%BC%96%E7%A8%8B/" title="大数据之多范式编程语言 Scala05_函数式编程"><img src="/oct25-xxxxx/img/cover_img/ctt48.png" onerror="this.onerror=null;this.src='/oct25-xxxxx/img/404.jpg'" alt="大数据之多范式编程语言 Scala05_函数式编程"/></a><div class="content"><a class="title" href="/oct25-xxxxx/2024/02/20/48%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%B9%8B%E5%A4%9A%E8%8C%83%E5%BC%8F%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80Scala05_%E5%87%BD%E6%95%B0%E5%BC%8F%E7%BC%96%E7%A8%8B/" title="大数据之多范式编程语言 Scala05_函数式编程">大数据之多范式编程语言 Scala05_函数式编程</a><time datetime="2024-02-20T12:05:11.000Z" title="发表于 2024-02-20 20:05:11">2024-02-20</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('/oct25-xxxxx/img/top_img/top_bg15.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2024 By Oct25-X</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">本地搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div id="rightMenu"><div class="rightMenu-group rightMenu-small"><div class="rightMenu-item" id="menu-backward"><i class="fa-solid fa-arrow-left"></i></div><div class="rightMenu-item" id="menu-forward"><i class="fa-solid fa-arrow-right"></i></div><div class="rightMenu-item" id="menu-refresh"><i class="fa-solid fa-arrow-rotate-right"></i></div><div class="rightMenu-item" id="menu-home"><i class="fa-solid fa-house"></i></div></div><div class="rightMenu-group rightMenu-line rightMenuOther"><a class="rightMenu-item menu-link" href="/archives/"><i class="fa-solid fa-archive"></i><span>文章归档</span></a><a class="rightMenu-item menu-link" href="/categories/"><i class="fa-solid fa-folder-open"></i><span>文章分类</span></a><a class="rightMenu-item menu-link" href="/tags/"><i class="fa-solid fa-tags"></i><span>文章标签</span></a></div><div class="rightMenu-group rightMenu-line rightMenuNormal"><a class="rightMenu-item" id="menu-translate"><i class="fa-solid fa-earth-asia"></i><span>繁简切换</span></a><div class="rightMenu-item" id="menu-darkmode"><i class="fa-solid fa-moon"></i><span>切换模式</span></div></div></div><div id="rightmenu-mask"></div><div><script src="/oct25-xxxxx/js/utils.js"></script><script src="/oct25-xxxxx/js/main.js"></script><script src="/oct25-xxxxx/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script><script src="/oct25-xxxxx/js/search/local-search.js"></script><div class="js-pjax"></div><script defer src="https://npm.elemecdn.com/jquery@latest/dist/jquery.min.js"></script><script defer data-pjax src="/js/rightMenu.js"></script><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="true"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="false"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>